package com.example.springbootnacos.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.springbootnacos.api.ApiServer;
import com.example.springbootnacos.api.UrlMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/")
public class TestController {
    
    @Autowired
    private ApiServer apiServer;
    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/mogoapi")
    public Object getMongoApi() throws Exception {
        //user 注册的服务名称
        String url = apiServer.hostPort(apiServer.userServer) + UrlMapping.user_init;
        ResponseEntity<JSONObject> resuult = restTemplate.getForEntity(url, JSONObject.class);
        System.out.println(resuult.getBody());
        return resuult.getBody();
    }

    @RequestMapping("/init")
    public Object initNacos() {
        Map map = new HashMap<String, String>();
        map.put("nacos", "nacos");
        return map;
    }
}
